
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/vector/advanced.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:30 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Potential Issues/Advanced Topics/Future Features in Physics/Vector Module &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="advanced.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="Scalar and Vector Field Functionality" href="fields.html" />
    <link rel="prev" title="Vector: Kinematics" href="kinematics.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="fields.html" title="Scalar and Vector Field Functionality"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="kinematics.html" title="Vector: Kinematics"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" accesskey="U">The Physics Vector Module</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Potential Issues/Advanced Topics/Future Features in Physics/Vector Module</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="potential-issues-advanced-topics-future-features-in-physics-vector-module">
<h1>Potential Issues/Advanced Topics/Future Features in Physics/Vector Module<a class="headerlink" href="#potential-issues-advanced-topics-future-features-in-physics-vector-module" title="Permalink to this headline">¶</a></h1>
<p>This document will describe some of the more advanced functionality that this
module offers but which is not part of the “official” interface. Here, some of
the features that will be implemented in the future will also be covered, along
with unanswered questions about proper functionality. Also, common problems
will be discussed, along with some solutions.</p>
<section id="inertia-dyadics">
<h2>Inertia (Dyadics)<a class="headerlink" href="#inertia-dyadics" title="Permalink to this headline">¶</a></h2>
<p>A dyadic tensor is a second order tensor formed by the juxtaposition of a pair
of vectors. There are various operations defined with respect to dyadics,
which have been implemented in <a class="reference internal" href="index.html#module-sympy.physics.vector" title="sympy.physics.vector"><code class="xref py py-obj docutils literal notranslate"><span class="pre">vector</span></code></a> in the form of
class <a class="reference internal" href="api/classes.html#sympy.physics.vector.dyadic.Dyadic" title="sympy.physics.vector.dyadic.Dyadic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.physics.vector.dyadic.Dyadic</span></code></a>. To know more, refer to the
<a class="reference internal" href="api/classes.html#sympy.physics.vector.dyadic.Dyadic" title="sympy.physics.vector.dyadic.Dyadic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.physics.vector.dyadic.Dyadic</span></code></a> and
<a class="reference internal" href="api/classes.html#sympy.physics.vector.vector.Vector" title="sympy.physics.vector.vector.Vector"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.physics.vector.vector.Vector</span></code></a> class APIs. Dyadics are used to
define the inertia of bodies within <a class="reference internal" href="../mechanics/index.html#module-sympy.physics.mechanics" title="sympy.physics.mechanics"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sympy.physics.mechanics</span></code></a>. Inertia
dyadics can be defined explicitly but the <code class="docutils literal notranslate"><span class="pre">inertia</span></code> function is typically
much more convenient for the user:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.mechanics</span> <span class="kn">import</span> <span class="n">ReferenceFrame</span><span class="p">,</span> <span class="n">inertia</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">ReferenceFrame</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">)</span>

<span class="go">Supply a reference frame and the moments of inertia if the object</span>
<span class="go">is symmetrical:</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">inertia</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">(N.x|N.x) + 2*(N.y|N.y) + 3*(N.z|N.z)</span>

<span class="go">Supply a reference frame along with the products and moments of inertia</span>
<span class="go">for a general object:</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">inertia</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="go">(N.x|N.x) + 4*(N.x|N.y) + 6*(N.x|N.z) + 4*(N.y|N.x) + 2*(N.y|N.y) + 5*(N.y|N.z) + 6*(N.z|N.x) + 5*(N.z|N.y) + 3*(N.z|N.z)</span>
</pre></div>
</div>
<p>Notice that the <code class="docutils literal notranslate"><span class="pre">inertia</span></code> function returns a dyadic with each component
represented as two unit vectors separated by a <code class="docutils literal notranslate"><span class="pre">|</span></code>. Refer to the
<a class="reference internal" href="api/classes.html#sympy.physics.vector.dyadic.Dyadic" title="sympy.physics.vector.dyadic.Dyadic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.physics.vector.dyadic.Dyadic</span></code></a> section for more information about dyadics.</p>
<p>Inertia is often expressed in a matrix, or tensor, form, especially for
numerical purposes. Since the matrix form does not contain any information
about the reference frame(s) the inertia dyadic is defined in, you must provide
one or two reference frames to extract the measure numbers from the dyadic.
There is a convenience function to do this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">inertia</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span><span class="o">.</span><span class="n">to_matrix</span><span class="p">(</span><span class="n">N</span><span class="p">)</span>
<span class="go">Matrix([</span>
<span class="go">[1, 4, 6],</span>
<span class="go">[4, 2, 5],</span>
<span class="go">[6, 5, 3]])</span>
</pre></div>
</div>
</section>
<section id="common-issues">
<h2>Common Issues<a class="headerlink" href="#common-issues" title="Permalink to this headline">¶</a></h2>
<p>Here issues with numerically integrating code, choice of <span class="math notranslate nohighlight">\(dynamicsymbols\)</span> for
coordinate and speed representation, printing, differentiating, and
substitution will occur.</p>
<section id="printing">
<h3>Printing<a class="headerlink" href="#printing" title="Permalink to this headline">¶</a></h3>
<p>The default printing options are to use sorting for <code class="docutils literal notranslate"><span class="pre">Vector</span></code> and <code class="docutils literal notranslate"><span class="pre">Dyadic</span></code>
measure numbers, and have unsorted output from the <code class="docutils literal notranslate"><span class="pre">vprint</span></code>, <code class="docutils literal notranslate"><span class="pre">vpprint</span></code>, and
<code class="docutils literal notranslate"><span class="pre">vlatex</span></code> functions. If you are printing something large, please use one of
those functions, as the sorting can increase printing time from seconds to
minutes.</p>
</section>
<section id="substitution">
<h3>Substitution<a class="headerlink" href="#substitution" title="Permalink to this headline">¶</a></h3>
<p>Substitution into large expressions can be slow, and take a few minutes.</p>
</section>
<section id="acceleration-of-points">
<h3>Acceleration of Points<a class="headerlink" href="#acceleration-of-points" title="Permalink to this headline">¶</a></h3>
<p>At a minimum, points need to have their velocities defined, as the acceleration
can be calculated by taking the time derivative of the velocity in the same
frame. If the 1 point or 2 point theorems were used to compute the velocity,
the time derivative of the velocity expression will most likely be more complex
than if you were to use the acceleration level 1 point and 2 point theorems.
Using the acceleration level methods can result in shorted expressions at this
point, which will result in shorter expressions later (such as when forming
Kane’s equations).</p>
</section>
</section>
<section id="advanced-interfaces">
<h2>Advanced Interfaces<a class="headerlink" href="#advanced-interfaces" title="Permalink to this headline">¶</a></h2>
<p>Here we will cover advanced options in: <code class="docutils literal notranslate"><span class="pre">ReferenceFrame</span></code>, <code class="docutils literal notranslate"><span class="pre">dynamicsymbols</span></code>,
and some associated functionality.</p>
<section id="referenceframe">
<h3>ReferenceFrame<a class="headerlink" href="#referenceframe" title="Permalink to this headline">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">ReferenceFrame</span></code> is shown as having a <code class="docutils literal notranslate"><span class="pre">.name</span></code> attribute and <code class="docutils literal notranslate"><span class="pre">.x</span></code>, <code class="docutils literal notranslate"><span class="pre">.y</span></code>,
and <code class="docutils literal notranslate"><span class="pre">.z</span></code> attributes for accessing the basis vectors, as well as a fairly
rigidly defined print output. If you wish to have a different set of indices
defined, there is an option for this. This will also require a different
interface for accessing the basis vectors.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.vector</span> <span class="kn">import</span> <span class="n">ReferenceFrame</span><span class="p">,</span> <span class="n">vprint</span><span class="p">,</span> <span class="n">vpprint</span><span class="p">,</span> <span class="n">vlatex</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">ReferenceFrame</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="n">indices</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="s1">&#39;j&#39;</span><span class="p">,</span> <span class="s1">&#39;k&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="p">[</span><span class="s1">&#39;i&#39;</span><span class="p">]</span>
<span class="go">N[&#39;i&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span><span class="o">.</span><span class="n">x</span>
<span class="go">N[&#39;i&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vlatex</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
<span class="go">&#39;\\mathbf{\\hat{n}_{i}}&#39;</span>
</pre></div>
</div>
<p>Also, the latex output can have custom strings; rather than just indices
though, the entirety of each basis vector can be specified. The custom latex
strings can occur without custom indices, and also overwrites the latex string
that would be used if there were custom indices.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.vector</span> <span class="kn">import</span> <span class="n">ReferenceFrame</span><span class="p">,</span> <span class="n">vlatex</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">ReferenceFrame</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="n">latexs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;n1&#39;</span><span class="p">,</span><span class="s1">&#39;</span><span class="se">\\</span><span class="s1">mathbf</span><span class="si">{n}</span><span class="s1">_2&#39;</span><span class="p">,</span><span class="s1">&#39;cat&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vlatex</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
<span class="go">&#39;n1&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vlatex</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
<span class="go">&#39;\\mathbf{n}_2&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vlatex</span><span class="p">(</span><span class="n">N</span><span class="o">.</span><span class="n">z</span><span class="p">)</span>
<span class="go">&#39;cat&#39;</span>
</pre></div>
</div>
</section>
<section id="dynamicsymbols">
<h3>dynamicsymbols<a class="headerlink" href="#dynamicsymbols" title="Permalink to this headline">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">dynamicsymbols</span></code> function also has ‘hidden’ functionality; the variable
which is associated with time can be changed, as well as the notation for
printing derivatives.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.vector</span> <span class="kn">import</span> <span class="n">dynamicsymbols</span><span class="p">,</span> <span class="n">vprint</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q1</span> <span class="o">=</span> <span class="n">dynamicsymbols</span><span class="p">(</span><span class="s1">&#39;q1&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q1</span>
<span class="go">q1(t)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dynamicsymbols</span><span class="o">.</span><span class="n">_t</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q2</span> <span class="o">=</span> <span class="n">dynamicsymbols</span><span class="p">(</span><span class="s1">&#39;q2&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q2</span>
<span class="go">q2(T)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q1</span>
<span class="go">q1(t)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q1d</span> <span class="o">=</span> <span class="n">dynamicsymbols</span><span class="p">(</span><span class="s1">&#39;q1&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vprint</span><span class="p">(</span><span class="n">q1d</span><span class="p">)</span>
<span class="go">q1&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dynamicsymbols</span><span class="o">.</span><span class="n">_str</span> <span class="o">=</span> <span class="s1">&#39;d&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vprint</span><span class="p">(</span><span class="n">q1d</span><span class="p">)</span>
<span class="go">q1d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dynamicsymbols</span><span class="o">.</span><span class="n">_str</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\&#39;</span><span class="s1">&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dynamicsymbols</span><span class="o">.</span><span class="n">_t</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that only dynamic symbols created after the change are different. The same
is not true for the <span class="math notranslate nohighlight">\(._str\)</span> attribute; this affects the printing output only,
so dynamic symbols created before or after will print the same way.</p>
<p>Also note that <code class="docutils literal notranslate"><span class="pre">Vector</span></code>’s <code class="docutils literal notranslate"><span class="pre">.dt</span></code> method uses the <code class="docutils literal notranslate"><span class="pre">._t</span></code> attribute of
<code class="docutils literal notranslate"><span class="pre">dynamicsymbols</span></code>, along with a number of other important functions and
methods. Don’t mix and match symbols representing time.</p>
</section>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Potential Issues/Advanced Topics/Future Features in Physics/Vector Module</a><ul>
<li><a class="reference internal" href="#inertia-dyadics">Inertia (Dyadics)</a></li>
<li><a class="reference internal" href="#common-issues">Common Issues</a><ul>
<li><a class="reference internal" href="#printing">Printing</a></li>
<li><a class="reference internal" href="#substitution">Substitution</a></li>
<li><a class="reference internal" href="#acceleration-of-points">Acceleration of Points</a></li>
</ul>
</li>
<li><a class="reference internal" href="#advanced-interfaces">Advanced Interfaces</a><ul>
<li><a class="reference internal" href="#referenceframe">ReferenceFrame</a></li>
<li><a class="reference internal" href="#dynamicsymbols">dynamicsymbols</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="kinematics.html"
                        title="previous chapter">Vector: Kinematics</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="fields.html"
                        title="next chapter">Scalar and Vector Field Functionality</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/modules/physics/vector/advanced.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="fields.html" title="Scalar and Vector Field Functionality"
             >next</a> |</li>
        <li class="right" >
          <a href="kinematics.html" title="Vector: Kinematics"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" >The Physics Vector Module</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Potential Issues/Advanced Topics/Future Features in Physics/Vector Module</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/vector/advanced.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:30 GMT -->
</html>